package dynamicProgramming.r_;

public class Class5 {


        public String longestPalindrome(String s) {
            int len = s.length();
            char[] chars = s.toCharArray();
            boolean[][] record = new boolean[len][len];
            int max=-1;
            String ans="";
            for (int i = len - 1; i >= 0; i--) {
                for (int j = i; j <= len - 1; j++) {
                    if (chars[j] == chars[i]) {
                        if (j - i <= 1) {
                            record[i][j] = true;
                        } else if (record[i + 1][j - 1]) {
                            record[i][j] = true;
                        }

                    }
                    if(record[i][j]==true&&max<(j-i+1)){
                        max=j-i+1;
                        ans=s.substring(i,j+1);

                    }
                }
            }
            return  ans;
        }

    public static void main(String[] args) {

        Class5 class5 = new Class5();
        System.out.println(class5.longestPalindrome("aacabdkacaa"));
    }

}
